#include "compile.h"
#include "hosts.h"
#include "util.h"

int dbd_compile_local(char *line){
	//dbd_execvp(line);
	return 0;
}

int dbd_is_link(const char *argv){
	if(strstr(argv, "ld") == argv)
		return 1;

	char * po = strstr(argv, ".o");
	if(po !=NULL && strstr(po+2, ".o")!=NULL){
		//two obj files, may be link
		return 1;
	}
	return 0;
}

int dbd_do_compile_timed(char * line){
	
	struct timeval begin_time, end_time;
	struct dbd_hostdef *host;
	gettimeofday(&begin_time, NULL);

	if(dbd_is_link(line)){
		return dbd_compile_local(line);
	}
	
	dbd_pick_one_host(&host);

	dbd_send_compile_argv(host,line);

	dbd_free_one_host(host);
	free(host);
	gettimeofday(&end_time, NULL);
}
